import unittest
from algebra import *
from numbertheory import *

class MatrixTestCase(unittest.TestCase):

    def setUp(self):
        self.m1 = Matrix([
            [1,2,3],
            [4,5,6]
            ])
        self.m2 = Matrix([
            [1,2],
            [3,4],
            [5,6]
            ])
        self.m3 = Matrix([
            [-1,-1],
            [-2,-2],
            [-3,-3]
            ])
    
    def testAdd(self):
        m = self.m2 + self.m3
        expect = Matrix([
            [0,1],
            [1,2],
            [2,3],
            ])
        self.assertEqual(expect,m)

    def testSub(self):
        m = self.m2 - self.m3
        expect = Matrix([
            [2,3],
            [5,6],
            [8,9],
            ])
        self.assertEqual(expect,m)

    def testMul(self):
        m = self.m1 * self.m2
        expect = Matrix([
           [22,28],
           [49,64],
            ])
        self.assertEqual(expect,m)


    def testTranspose(self):
        m = self.m1.transpose()
        expect = Matrix([
        [1,4],
        [2,5],
        [3,6]
            ])
        self.assertEqual(expect,m)
    def testInvert(self):
        m = Matrix([
            [Fraction(2,1),Fraction(-1,1),Fraction(0,1)],
            [Fraction(-1,1),Fraction(2,1),Fraction(-1,1)],
            [Fraction(0,1),Fraction(-1,1),Fraction(2,1)],
            ])
        im = ~m

        expect = Matrix([
[Fraction(3,4), Fraction(1,2), Fraction(1,4)],
[Fraction(1,2), Fraction(1,1), Fraction(1,2)],
[Fraction(1,4), Fraction(1,2), Fraction(3,4)],
            ])
        self.assertEqual(expect,im)
##        

    def testSolve(self):
        m = Matrix([
            [Fraction(2,1),Fraction(1),Fraction(-1,1)],
            [Fraction(-3,1),Fraction(-1),Fraction(2,1)],
            [Fraction(-2,1),Fraction(1),Fraction(2,1)],
            ])

        value = Matrix([
            [8,],
            [-11,],
            [-3,],
            ])
        print solve_line_equations(m,value)
if __name__=="__main__":unittest.main()
